<template>
    <view class="container">

        <!-- 投诉部分 -->
        <view class="section">
            <view class="section-title">
                <text class="complain-target">投诉对象</text>
                <view class="target-info" @click="checkTarget">
                    <text class="complain-info" >{{ currentTargetData.nickname }}{{currentTargetData.phone}}</text>
                    <image class="complain-icon" src="/static/personalCenter/details.png" mode="aspectFill"></image>
                </view>
            </view>
            <view class="complaint-input">
                <textarea placeholder="投诉详细原因，仅平台方可查看" maxlength="100" v-model="complaintDetail"
                    @input="countComplaintChars"></textarea>
                <text class="char-count">{{ complaintCharCount }}/100</text>
            </view>
        </view>

        <!-- 提交按钮 -->
        <view class="submit-btn" @click="submit">提 交</view>
        <!-- 投诉对象 -->
        <u-picker :show="isShowTarget" :columns="[columnsTarget]" keyName="label" closeOnClickOverlay
            @confirm="confirmTargetPicker" @cancel="closeTargetPicker"></u-picker>
    </view>
</template>

<script>
export default {
    data() {
        return {
            isShowTarget: false,
            complaintDetail: "",
            complaintCharCount: 0,
            columnsTarget: [],
            currentTargetData: {}
        };
    },
    onLoad(options) {
        this.currentTripId = options.id
    },
    onShow(options) {
        // 获取投诉对象
        this.getMotoristsTripDetails()
    },
    methods: {
        async getMotoristsTripDetails() {
            try {
                const res = await this.$http.get(`/h5/user/line/detail/${this.currentTripId}`)
                if (res.data && res.data.lineOrders.length > 0) {
                    this.currentTargetData = res.data.lineOrders[0].user
                    this.columnsTarget = res.data.lineOrders.map(i => {
                        return {
                            label: i.user.nickname,
                            value: i.user.phone,
                        }
                    })
                }



            } catch (error) {
            }
        },
        closeTargetPicker() {
            this.isShowTarget = false;
        },
        confirmTargetPicker(e) {
            this.formData.seats = e.value[0].value;
            this.closeTargetPicker();
        },
        checkTarget() {
            this.isShowTarget = true
        },
        countComplaintChars(e) {
            this.complaintCharCount = e.detail.value.length;
        },
        // 提交投诉
        async submit() {
            if (!this.complaintDetail) {
                uni.showToast({
                    title: "请输入投诉详细原因",
                    icon: "none",
                });
                return;
            }
            let params = {
                order_id: this.currentTripId,
                content: this.complaintCharCount
            }
            try {
                const res = await this.$http.post(`/h5/user/line/complaint`, params);
                uni.showToast({
                    title: "提交成功",
                    icon: "success",
                });
                setTimeout(() => {
                    uni.navigateBack();
                }, 1000);

            } catch (error) { }

        },
    },
};
</script>

<style scoped>
.container {
    padding: 20rpx 26rpx;
    height: 100%;
}

.section {
    background-color: #fff;
    padding: 26rpx 40rpx;
    margin-bottom: 20rpx;
    border-radius: 16rpx;
    height: 100%;
}

.section-title {
    margin-bottom: 26rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title .complain-target {
    font-size: 32rpx;
    font-weight: 500;
    color: #0B1F20;
}

.target-info {
    display: flex;
    align-items: center;
}

.section-title .complain-info {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
}

.complain-icon {
    width: 28rpx;
    height: 28rpx;
}

.complaint-input {
    position: relative;
}

textarea {
    width: 100%;
    height: 320rpx;
    padding: 28rpx 24rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
    background: #F5F5F6;
    border-radius: 16rpx;
    box-sizing: border-box;
}

.char-count {
    position: absolute;
    right: 24rpx;
    bottom: 28rpx;
    font-size: 28rpx;
    color: #999;
}


.submit-btn {
    background: linear-gradient(90deg, #ff3f39 0%, #ff7937 100%);
    color: #fff;
    text-align: center;
    padding: 24rpx 0;
    border-radius: 16rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 500;
    font-size: 36rpx;
    color: #FFFFFF;
    margin-bottom: 20rpx;
}
</style>
